package com.study.jyg.rxjava2study.activity;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.android.material.appbar.AppBarLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;

import com.study.jyg.rxjava2study.R;
import com.study.jyg.rxjava2study.activity.mywidget.MyWidgetActivity;
import com.study.jyg.rxjava2study.base.BasicActivity;
import com.study.jyg.rxjava2study.utils.AdapterInit;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 自定义控件选择页面
 */
public class CustomControlActivity extends BasicActivity {


    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.appBar)
    AppBarLayout appBar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private String[] datas = {"design库", "自定义控件"};
    private BaseQuickAdapter< String, BaseViewHolder> adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_custom_control;
    }

    @Override
    protected void initView() {
        toolbar.setTitle("自定义控件");
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(v -> finish());
        initAdapter();
    }

    private void initAdapter(){
        adapter = AdapterInit.initRecyclerView( recyclerView, R.layout.item_recyclerview_textview, Arrays.asList(datas), new LinearLayoutManager(mContext), (helper, item) -> {
            helper.setText(R.id.tvItem, item);
        }, (adapter1, view, position) -> {
            if ( 0 == position){
                startActivity(DesignSelectActivity.class);
            }else if ( 1 == position){
                startActivity(MyWidgetActivity.class);
            }
        });
    }
}
